var store = {
    reducer,
    dispatch,
    state: {
        count: 0
    },
    getState
}

// 初始化值
store.state = store.reducer(store.state, { type: 'init' })


// 每次通过dispatch调用的reducer方法，
function reducer(state = { count: 0 }, action) {
    switch (action.type) {
        case 'add':
            state.count++;
            break;
        case 'de':
            state.count--;
            break;
        default:
    }
    return state
}

//分发的方法
function dispatch(action) {
    this.state = store.reducer(store.state, action)
}

//获取状态
function getState() {
    return store.state;
}

export default store;